﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Navigation;
using SoftwareLogistics.SharepointClient.Library;
using SoftwareLogistics.SharepointClient.Services;

namespace SoftwareLogistics.SharepointClient.Silverlight.Views
{
    public partial class Settings : Page
    {
        Sync _sync;

        public Settings()
        {
            InitializeComponent();
            _sync = new Sync();
            _sync.SyncCompleted += (sender, args) =>
                {
                    Dispatcher.BeginInvoke(() =>
                        {
                            Common.SyncService.LastSync = DateTime.Now;
                            LastSyncValue.Text = Common.SyncService.LastSync.ToString();
                            App.ProgressDialog.Close();
                        });

                };
        }

        // Executes when the user navigates to this page.
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            LastSyncValue.Text = Common.SyncService.LastSync.ToString();
        }

        private void SyncNow_Click(object sender, RoutedEventArgs e)
        {
            App.ProgressDialog.Show();
            _sync.SyncNow("pm");
        }

    }
}
